<template>
	<view class="content">
		<view class="info">
			<view class="list">
				<text class="text huaduo" v-if="theWay == 2">
					{{ data.post_cost | curreny }}
				</text>
				<text class="text" v-else-if="theWay == 1">
					￥{{ data.post_cost }}
				</text>
				<text class="text" v-else-if="theWay == 3">
					￥{{ data.post_cost }}
				</text>
				<text class="text1">支付金额</text>
			</view>

			<view class="list1">
				<text class="text">支付方式</text>

				<text class="text text1">{{ list }}</text>
			</view>
		</view>
		<view class="applyToSettleIn">
			<button type="default" @click="confirmPayment()">确认支付</button>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			data: {}, // 参数
			//data1: {},

			list: '',
			theWay: ''
		};
	},
	methods: {
		// 培训报名
		async confirmPayment() {
			const res = await this.$u.post(
				'/api/Allnews/train_bm',
				{
					article_id: this.data.id,
					name: this.data.name,
					mobile: this.data.mobile,
					idcard: this.data.idCrd
				},
				{
					'XX-Token': uni.getStorageSync('token'),
					'XX-Device-Type': 'wxapp'
				}
			);
			console.log('培训报名 >>  ', res);

			// if (!res.code) return ;
			if (this.theWay == 1) {
				//this.data1 = res.data;
				this.shengqing(res.data);
			} else if (this.theWay == 2) {
				uni.$showMsg(res.msg);
				setTimeout(function() {
					uni.reLaunch({
						url: '../../peixun/peixun'
					});
				}, 1000);
			} else {
				uni.$showMsg(res.msg);
				setTimeout(function() {
					uni.reLaunch({
						url: '../../peixun/peixun'
					});
				}, 1000);
			}

			
		},
		// 支付
		async shengqing(data) {
			uni.requestPayment({
				provider: 'wxpay',
				timeStamp: data.timeStamp,
				nonceStr: data.nonceStr,
				package: data.package,
				signType: data.signType,
				paySign: data.paySign,
				success: function(res) {
					console.log('success:' + JSON.stringify(res));
					uni.$showMsg('支付成功!');
					setTimeout(function() {
						uni.reLaunch({
							url: '../../peixun/peixun'
						});
					}, 1000);
				},
				fail: function(err) {
					console.log('fail:' + JSON.stringify(err));
					uni.$showMsg('支付失败!11');
				}
			});
		}
	},
	onLoad(e) {
		this.data = JSON.parse(e.list);
		console.log('this.data!!! :>> ', this.data);
		console.log('theWay', uni.getStorageSync('theWay'));
		this.theWay = uni.getStorageSync('theWay');

		if (this.theWay == 1) {
			this.list = '微信支付';
		} else if (this.theWay == 2) {
			this.list = '鲜花';
		} else {
			this.list = '免费';
		}
	},
	filters: {
		curreny: function(data) {
			console.log('data :>> ', data);
			data = Number(data).toFixed(2);
			if (data == parseInt(data)) {
				data = parseInt(data);
			}
			return data;
		}
	}
};
</script>

<style lang="scss">
.content {
	padding-top: 20rpx;
	.info {
		width: 690rpx;
		height: 447rpx;
		margin: 0 auto;
		background: #ffffff;
		border-radius: 20rpx;
		.list {
			display: flex;
			flex-direction: column;
			align-items: center;
			padding-top: 63rpx;

			.huaduo::after {
				content: '';
				display: inline-block;
				vertical-align: middle;
				margin-left: 10rpx;
				//margin-top: -5rpx;
				width: 36rpx;
				height: 54rpx;
				background: url(https://s3.ax1x.com/2020/11/27/DDBJld.png)
					no-repeat center;
				background-size: cover;
			}

			.text {
				// width: 190rpx;
				// height: 45rpx;
				display: flex;
				align-items: center;
				font-size: 60rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #ff0000;
			}
			.text1 {
				// width: 141px;
				// height: 34px;
				font-size: 36rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #333333;
			}
		}

		.list1 {
			// display: flex;
			// flex-direction: column;
			padding: 71rpx 0 0 22rpx;
			display: flex;
			flex-direction: column;
			.text {
				font-size: 36rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #333333;
			}
			.text1 {
				font-weight: bold;
				color: #ff0000;
			}
		}
	}
	.applyToSettleIn {
		button {
			margin-top: 404rpx;
			width: 690rpx;
			height: 100rpx;
			background: #671729;
			border-radius: 50rpx;

			font-size: 36rpx;
			font-family: 'Microsoft YaHei', PingFang SC;
			font-weight: 500;
			color: #ffffff;
		}
	}
}
</style>
